package org.monkey.common.constant.util;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import java.io.File;
import java.nio.charset.StandardCharsets;

public class Main {
  public static void main(String[] args) throws InterruptedException {
   String s = "{\"Head\":{},\"Data\":\"{\\\"pageNo\\\":%s,\\\"rowsPerPage\\\":100,\\\"paramName\\\":\\\"CiqOriginPlace\\\",\\\"filterField\\\":null,\\\"filterValue\\\":null}\"}";
   String url = "https://www.singlewindow.cn/access/ui/1657016319868/Param002";
    File file = new File("D:/CiqOriginPlace.json");
    FileUtil.appendString("[\n",file, StandardCharsets.UTF_8);
    for (int i = 1; i<42; i++) {
      String jsonParam = String.format(s,i);
      String resultStr = HttpClientUtil.doPostJson(url,jsonParam,null);
      JSONObject jsonObject = JSONUtil.parseObj(resultStr);
      JSONObject js = jsonObject.getJSONObject("data");
      JSONArray jsonArray = js.getJSONArray("data");
      for (int j = 0; j < jsonArray.size(); j++) {
        JSONObject jo = jsonArray.getJSONObject(j);
        FileUtil.appendString(jo.toString()+",\n",file, StandardCharsets.UTF_8);
      }
      Thread.sleep(1000);
    }
    FileUtil.appendString("]",file, StandardCharsets.UTF_8);
  }

}
